//
//  ToolManagerViewController.m
//  智积分
//
//  Created by Cynic on 2018/7/18.
//  Copyright © 2018年 Cynic. All rights reserved.
//

#import "ToolManagerViewController.h"
#import <ShareSDK/ShareSDK.h>
#import <ShareSDKUI/ShareSDK+SSUI.h>
#import "CentRedBagViewController.h"
@interface ToolManagerViewController ()

@end

@implementation ToolManagerViewController


-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    if (cx_hit == 812) {
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
    }
    else{
        [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleDefault;
    };
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

-(instancetype)init{
    self = [super initInChildWithFrame:CGRectMake(0, cxsingler.topdis - cxsingler.navitop, cx_wid, cx_hit - cxsingler.topdis - cxsingler.bottomdis - 50 + cxsingler.navitop)];
    self.view.backgroundColor = bggrayColor;
    [self viewLoad];
    //    [self dataLoad];
    //    //    self.view.frame = CGRectMake(0, cxsingler.topdis, cx_wid, cx_hit - cxsingler.topdis - cxsingler.bottomdis - 50);
    //    _isseller = NO;
    //    [self viewLoad];
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

-(void)viewLoad{
    [self setNavigationViewWithTitle:@"工具" WithCanPop:NO WithPopData:@"" WithPopisString:YES WithHasRightOperation:YES WithrightOperationData:@"xx" WithRightisString:YES WithNavigationColor:[UIColor whiteColor] withBgView:self.view];
    self.centerTitle.textColor = [UIColor blackColor];
    NSArray *icons = @[@[@"积分红包",@"jifenhongbao"]];
    CGFloat partdis = 10;
    CGFloat partwid = (cx_wid - 50) / 4;
    for (NSInteger index = 0; index < icons.count; index ++) {
        UIButton *partICon = [[UIButton alloc] initWithFrame:CGRectZero];
        partICon.backgroundColor = [UIColor whiteColor];
        [self.view addSubview:partICon];
        
        [partICon mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(partdis + (partdis + partwid) * (index % 4 ));
            make.top.mas_equalTo(cxsingler.topdis + 44 + partdis + (partdis + partwid) * (index / 4));
            make.size.mas_equalTo(CGSizeMake(partwid, partwid));
        }];
        
//        [partICon setTitle:icons[index][0] forState:UIControlStateNormal];
        [partICon LoadNamelableWithFrame:CGRectMake(0, partwid - 22, partwid, 12) withFont:12 withTextColor:[UIColor ColorWithHex:@"646464" withAlpha:1] withEditEnabel:NO WithtextAli:NSTextAlignmentCenter];
        partICon.namelabel.text = icons[index][0];
        [partICon setImage:[UIImage imageNamed:icons[index][1]] forState:UIControlStateNormal];
        [partICon setImageEdgeInsets:UIEdgeInsetsMake(-15, 0, 0, 0)];
        [partICon cx_eventsBlockHandler:^{
            if (index == 0) {
                
                CentRedBagViewController *nextVC = [CentRedBagViewController alloc];
                [self.navigationController pushViewController:nextVC animated:YES];
                return ;
                NSString *AccountID = cxsingler.loginrequest[@"admin"][@"shop_id"];
                NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
                    [shareParams SSDKSetupShareParamsByText:@"分享内容"
                     
                                                         images:[[NSBundle mainBundle] pathForResource:@"COD13" ofType:@"jpg"]
                     
                                                             url:[NSURL URLWithString:[NSString stringWithFormat:@"http://{{%@}}/shareRedPacket?shop_id=%@&red_packet_id=%@",baseUrl,AccountID,@"xyz"]]
                     
                                                           title:@"分享标题"
                     
                                                           type:SSDKContentTypeAuto];
                [ShareSDK showShareActionSheet:nil items:nil shareParams:shareParams onShareStateChanged:^(SSDKResponseState state, SSDKPlatformType platformType, NSDictionary *userData, SSDKContentEntity *contentEntity, NSError *error, BOOL end) {
                    switch (state) {
                            
                                                  case SSDKResponseStateSuccess:
                            
                                                  {
                                
                                                          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"分享成功"
                                                                                    
                                                                                                                                                                  message:nil
                                                                                    
                                                                                                                                                                  delegate:nil
                                                                                    
                                                                                                                                                        cancelButtonTitle:@"确定"
                                                                                    
                                                                                                                                                        otherButtonTitles:nil];
                                
                                                          [alertView show];
                                
                                                          break;
                                
                                                      }
                            
                                                  case SSDKResponseStateFail:
                            
                                                  {
                                
                                UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"分享失败"          message:[NSString stringWithFormat:@"%@",error]            delegate:nil   cancelButtonTitle:@"OK"  otherButtonTitles:nil, nil];
                                                          [alert show];
                                                          break;
                                                      }
                                                  default:
                                                      break;
                                          }
                                  }];
            }
        } forControlEvents:UIControlEventTouchUpInside];
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
